#include<bits/stdc++.h>
using namespace std;
int d[100005],v[100005],a[100005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        int n,m,L,V,cnt=0,lst=0,k;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++) cin>>k,lst=max(k,lst);
        for(int i=1;i<=n;i++) if(v[i]>V&&d[i]<=lst) cnt++;
        cout<<cnt<<' '<<m-1<<endl;
    }
    return 0;
}